package com.freeman.cement.controller;

import com.freeman.cement.annotation.NeedRole;
import com.freeman.cement.entity.ResponseResult;
import com.freeman.cement.entity.ShiftRecord;
import com.freeman.cement.service.ShiftService;
import com.freeman.cement.exception.AppException;
import com.freeman.cement.exception.AppExceptionCodeMsg;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 *  交接班管理
 */
@RestController
@RequestMapping("/dutyshift")
@CrossOrigin    //允许跨域访问
public class DutyShiftController {
    @Resource
    private ShiftService shiftService;

    /**
     * 值班人员提请交班
     * @param userId
     * @param dutyRoomId
     * @param memo
     * @return
     */
    @NeedRole("管理员||值班员")
    @RequestMapping(value = "/submitOffDuty", method = RequestMethod.POST)
    public ResponseResult submitOffDuty(@RequestParam(value = "userId", required = true) Integer userId,
                                        @RequestParam("dutyRoomId") int dutyRoomId, String memo) {
        if(userId == null) {
            throw new AppException(AppExceptionCodeMsg.ID_IS_NULL);
        }
        return shiftService.submitOffDuty(userId, dutyRoomId, memo);
    }

    /**
     * 值班人员提请接班
     * @param userId
     * @param dutyRoomId
     * @return
     */
    @NeedRole("管理员||值班员")
    @RequestMapping(value = "/submitOnDuty", method = RequestMethod.POST)
    public ResponseResult submitOnDuty(@RequestParam("userId") int userId,
                                     @RequestParam("dutyRoomId") int dutyRoomId) {
        return shiftService.submitOnDuty(userId, dutyRoomId);
    }

    /**
     * 交接班历史记录查询
     * @param shiftRecord
     * @param startTime
     * @param endTime
     * @param pageNo
     * @param pageSize
     * @return
     */
    @NeedRole("管理员||值班员")
    @RequestMapping(value = "/selectShiftRecord", method = RequestMethod.POST)
    public ResponseResult selectShiftRecord(ShiftRecord shiftRecord, String startTime, String endTime, @RequestParam("pageNo") int pageNo, @RequestParam("pageSize") int pageSize) {
        return shiftService.selectShiftRecord(shiftRecord, startTime, endTime, pageNo, pageSize);
    }

}